package mapReader;

import java.util.ArrayList;
import java.util.List;

import mapReader.commandos.Barcode;
import mapReader.commandos.CancelPlan;
import mapReader.commandos.Captured;
import mapReader.commandos.Commando;
import mapReader.commandos.Discover;
import mapReader.commandos.Join;
import mapReader.commandos.Name;
import mapReader.commandos.Pacman;
import mapReader.commandos.Ping;
import mapReader.commandos.Plan;
import mapReader.commandos.Position;

public class CommandoManager {
	
	private List<Commando> commandos;

	public CommandoManager(GhostProtocol ghostProtocol){
		setCommandos(new ArrayList<Commando>());
		initCommandos(ghostProtocol);
	}
	
	//Init, Constructor
	private void initCommandos(GhostProtocol ghostProtocol){
		addCommando(new Join(ghostProtocol));
		addCommando(new Barcode(ghostProtocol));
		addCommando(new CancelPlan(ghostProtocol));
		addCommando(new Captured());
		addCommando(new Discover(ghostProtocol));
		addCommando(new Join(ghostProtocol));
		addCommando(new Name(ghostProtocol));
		addCommando(new Pacman(ghostProtocol));
		addCommando(new Plan(ghostProtocol));
		addCommando(new Position(ghostProtocol));
		addCommando(new Ping(ghostProtocol));
	}
		
	public List<Commando> getCommandos(){
		return commandos;
	}
	
	private void setCommandos(List<Commando> commandos){
		this.commandos = commandos;
	}
		
		
	//CommandoMap
	private void addCommando(Commando commando){
		//TODO checks
		getCommandos().add(commando);
	}
	
	public Commando getCommandoMetNaam(String naam){
		//TODO doc
		for(Commando commando : getCommandos())
			if(commando.getNaam().equals(naam))
				return commando;
		
		
		throw new CommandoOnbekendException();
	}
	
	public boolean heeftAnoniemCommandoMetNaam(String naam)
	{
		for(Commando commando: commandos)
		{
			if(commando.isAnoniem())
				if(commando.getNaam().equals(naam))
					return true;
		}
		
		return false;
	}
}
